<?php

class FacebookLike extends CWidget {

    public $url;
    public $height;

    public function run() {
        if ( empty($this->url) ) {
            $rootDir = Yii::app()->params['document_root'];
            $jsonFilePath = Yii::app()->params['components_dir'] . 'contact.json';
            $data = json_decode(file_get_contents($jsonFilePath), true);
            $this->url = $data['info']['0']['fanpage'];
        }
        if ( $this->height == '') $this->height = 200;
            
        echo <<< EOD
<div id="fb-root"></div>
<script>(function(d, s, id) {
  var js, fjs = d.getElementsByTagName(s)[0];
  if (d.getElementById(id)) return;
  js = d.createElement(s); js.id = id;
  js.src = "//connect.facebook.net/vi_VN/all.js#xfbml=1";
  fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));</script>

<div class="fb-like-box" data-href="$this->url"
     data-width="300" data-height="$this->height"
     data-show-faces="true" data-stream="false"
     data-show-border="true" data-header="false"
     style="background-color: #fff;">
</div>
EOD;
    }

}